package edu.qd.learn.day04;

import java.util.Arrays;

/**
 * 数组帮助类的基本操作
 *
 * @author 布衣
 */
public class LearnArray01 {

    public static void main(String[] args) {
        //fill  sort binarySearch  toString
        int[] arr02 = new int[100];
        Arrays.fill(arr02, 9);

        System.out.println(Arrays.toString(arr02));

        int[] arr03 = {23, 34, 1, 2, 3, 6, 7, 9, 5};
//        [0,4)
        Arrays.sort(arr03,0,4);

        System.out.println(Arrays.toString(arr03));
//        System.out.println(0(n));
        for (int i = 0; i < arr03.length; i++) {
            if (arr03[i] == 7) {
                System.out.println("有7");
                break;
            }
        }

        //二分  二分查找  折半查找 （两指针）
        int[] arr04 = {1, 2, 3, 5, 6, 7, 9, 23, 34};
        int left = 0;
        int right = arr04.length - 1;
        int middle = 0;
        while (left <= right) {
            middle = (left + right) >>> 1;
            if (arr04[middle] == 7) {
                System.out.println("有");
                break;
            } else if (arr04[middle] < 7) {
                left = middle + 1;
            } else {
                right = middle - 1;
            }
        }

        Arrays.binarySearch(arr04, 7);
    }

}
